package com.cdyx.outsideprescription.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cdyx.outsideprescription.dto.RecipeInfoDto;
import com.cdyx.outsideprescription.dto.diagnosesDto;
import com.cdyx.outsideprescription.entity.TbPsnInfo;
import com.cdyx.outsideprescription.mapper.TbPrecriptiondiagMapper;
import com.cdyx.outsideprescription.mapper.TbPsnInfoMapper;
import com.cdyx.outsideprescription.mapper.TbRecipeinfoMapper;
import com.cdyx.outsideprescription.service.ITbPsnInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdyx.outsideprescription.util.CalendarUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiang dongqiong
 * @since 2021-12-18
 */
@Service("psnInfoServiceImpl")
public class TbPsnInfoServiceImpl extends ServiceImpl<TbPsnInfoMapper, TbPsnInfo> implements ITbPsnInfoService {
    @Autowired
    private TbPsnInfoMapper psnInfoMapper;
    @Autowired
    private TbPrecriptiondiagMapper precriptiondiagMapper;
    @Autowired
    private TbRecipeinfoMapper recipeinfoMapper;

    @Override
    public Map<String,Object> dealPsnInfo( String visitNo,String org_med_type) {
        Map<String,Object> indexInfo=new HashMap<>();
        QueryWrapper<TbPsnInfo> psn=new QueryWrapper<>();
        psn.eq(!visitNo.isEmpty(),"psn_registration",visitNo);
        TbPsnInfo psnInfo = psnInfoMapper.selectOne(psn);
       // List<diagnosesDto> diaglist=precriptiondiagMapper.selectDiagList(visitNo);
        //List<RecipeInfoDto> recipeDetailsDtoList= recipeinfoMapper.selectRecipeIList(visitNo);
        indexInfo.put("diaglist",null);
        indexInfo.put("recipeList",null);
        if (psnInfo==null){
            if (org_med_type.equals("11")){
                List<Map<String, String>> mothYear = CalendarUtil.getYearMoth();
                psnInfoMapper.insertByInfo(visitNo,mothYear,org_med_type);
            }else {
                psnInfoMapper.insertByInfozy(visitNo);
            }
            TbPsnInfo psnInfo1 = psnInfoMapper.selectById(visitNo);
            indexInfo.put("psnInfo",psnInfo1);
        }else{
            indexInfo.put("psnInfo",psnInfo);
        }
        return indexInfo;
    }
}
